package com.shop.reply.controller;

import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import com.shop.reply.dao.ShopBoardReplyDao;
import com.shop.reply.domain.ShopBoardReplyCommand;
import com.shop.reply.validator.ShopBoardReplyValidator;

@Controller
public class ShopBoardReplyWriteController {
	
	private Logger log = Logger.getLogger(this.getClass());
	@Autowired
	private ShopBoardReplyDao shopBoardReplyDao;
	
	@RequestMapping(value="/shop/boardreplywrite.do")
	public String submit(ShopBoardReplyCommand shopBoardReplyCommand,
												BindingResult result){
		if(log.isDebugEnabled()){
			log.debug("ShopBoardReplyCommand : " +shopBoardReplyCommand);
		}
		System.out.println(shopBoardReplyCommand);
		new ShopBoardReplyValidator().validate(shopBoardReplyCommand, result);
		int sb_num = shopBoardReplyCommand.getSb_num();	
		shopBoardReplyDao.insertShopBoardReply(shopBoardReplyCommand);
				return "redirect:/shop/boarddetail.do?sb_num="+sb_num;
	}
}
